/*
 * 根据id删除数据
 */
function delById(prefix,id){
	
	if(!window.confirm("确认删除？")){
		return ;
	}

	var url=prefix+"/companyAdmin/delete";
	$.post(url,{"id":id},function(data){
		alert("删除成功");
		location.reload(true);
	},'json');
}

//审核通过
function passById(prefix,id){
	if(!window.confirm("确认审核？")){
		return ;
	}
	
	var url=prefix+"/product/pass";
	$.post(url,{"id":id},function(data){
		alert("操作成功");
		location.reload(true);
	},'json');
}



/*
 * 根据多个id删除数据
 * @param {Object} prefix
 */
function delByIds(prefix){
	
	var str="";
	var checkArray = document.getElementsByName("chk");
	for (var i = 0; i < checkArray.length; i++) {
		if(checkArray[i].checked){
			str += checkArray[i].value + ",";
		}
	}
	var dot = str.lastIndexOf(",");
	if(dot==-1){
		alert("请选择要删除的商品");
		return;
	}else{
		str = str.substring(0,dot);
	}
	
	if(!window.confirm("确认删除？")){
		return;
	}
	
	var url=prefix+"/companyAdmin/deleteMany";
	$.post(url,{"idStr":str,},function(data){
		location.reload(true);
	},'json');
	
}

/*
 * 根据多个id审批通过数据
 * @param {Object} prefix
 */
function selectUser(){
	  var obj=document.getElementById("userNo");
	  var type=document.getElementsByName("tradeType");
	  var typeValue=0;
	  for (var i=0;i<type.length;i++){
	   if(type.item(i).checked){
		   typeValue=type.item(i).value;
		   break;
	   }
	  }
	  var postNo=document.getElementById("postNo").value;
	  var posNum=document.getElementById("posNum").value;
	  var cardNo=obj.value;
	    if(cardNo==""){
			alert("请填写正确的会员信息。");
			return false;
	    }
	    var money=document.getElementById("money").value;
	    var remoney=document.getElementById("remoney").value;
	    if(money==""||isNaN(money)){
			alert("请输入正确的金额。");
			document.getElementById("money").value="";
			document.getElementById("remoney").value="";
			return false;
	    }
	    if(remoney==""||isNaN(remoney)||money!=remoney){
			alert("确认金额不一致。请重新输入");
			document.getElementById("money").value="";
			document.getElementById("remoney").value="";
			return false;
	    }
	    if(typeValue==1&&posNum=="")
	    	{
	    	alert("请填写POS票号。");
			return false;
	    	}
	    if(postNo=="")
    	{
    	alert("请填写收据单号。");
		return false;
    	}
}
function addMoney(prefix){
	
	  var obj=document.getElementById("userNo");
	  var cardNo=obj.value;
	    if(cardNo==""){
			alert("请填写正确的会员信息。");
			return;
	    }
	    var money=document.getElementById("money").value;
	    if(isNaN(money)){
			alert("请输入正确的金额。");
			return;
	    }
	
	var url=prefix+"/companyAdmin/addAccountBalance";
	$.post(url,{"userNo":cardNo,"money":money},function(data){
		alert("充值成功");
	},'json');
	
}
/*确定楼
 * @param {Object} prefix
 */
function checkBuilding(prefix){
	var community = document.getElementById("community");
	var cNo=community.options[community.selectedIndex].value;
	if(cNo!="")
	{
//查询关联的用户
var url=prefix+"/companyAdmin/checkBuilding";
$.post(url,{"community":cNo},function(data,textStatus){
	if(textStatus == "success") {
		$("#buildNo").empty();
		$("#unitNo").empty();
		$("#roomNo").empty();
		var xmzztOptions = "";
	    $.each(data,function(idx,item){
	    	if($("#buildId").val==item.id)
	    		xmzztOptions += "<option value='"+item.id+"' selected>" + item.buildingNo + "</option>";
	    	else
	    	xmzztOptions += "<option value='"+item.id+"'>" + item.buildingNo + "</option>";
		});
	    var xmzztBegin = "<option value=''>请选择</option>";

	    $("#buildNo").append(xmzztBegin).append(xmzztOptions);
	   
	}
},"json"); 

	
	}
}



/*确定单元
 * @param {Object} prefix
 */
function checkUnit(prefix){
	var buildNo = document.getElementById("buildNo");
	var bNo=buildNo.options[buildNo.selectedIndex].value;
	if(bNo!="")
	{
//查询关联的用户
var url=prefix+"/companyAdmin/checkUnit";
$.post(url,{"build":bNo},function(data,textStatus){
	if(textStatus == "success") {
		$("#unitNo").empty();
		$("#roomNo").empty();
		var xmzztOptions = "";
	    $.each(data,function(idx,item){
	    	if($("#unitId").val==item.id)
	    		xmzztOptions += "<option value='"+item.id+"' selected>" + item.unitNo + "</option>";
	    	else
	    	xmzztOptions += "<option value='"+item.id+"'>" + item.unitNo + "</option>";
		});
	    var xmzztBegin = "<option value=''>请选择</option>";
	    $("#unitNo").append(xmzztBegin).append(xmzztOptions);
	}
},"json"); 	
	}
}

/*确定门牌
 * @param {Object} prefix
 */
function checkRoom(prefix){
	var unitNo = document.getElementById("unitNo");
	var uNo=unitNo.options[unitNo.selectedIndex].value;
	if(uNo!="")
	{
//查询关联的用户
var url=prefix+"/companyAdmin/checkRoom";
$.post(url,{"unit":uNo},function(data,textStatus){
	if(textStatus == "success") {
		$("#roomNo").empty();
		var xmzztOptions = "";
	    $.each(data,function(idx,item){
	    	if($("#roomId").val==item.id)
	    		xmzztOptions += "<option value='"+item.id+"' selected>" + item.roomNo + "</option>";
	    	else
	    	xmzztOptions += "<option value='"+item.id+"'>" + item.roomNo + "</option>";
		});
	    var xmzztBegin = "<option value=''>请选择</option>";
	    $("#roomNo").append(xmzztBegin).append(xmzztOptions);
	}
},"json"); 	
	}
}

function checkMobile(prefix)
{
	var mobile=document.getElementById("mobile").value;
	//查询关联的用户
	var url=prefix+"/companyAdmin/checkUser";
	$.post(url,{"mobile":mobile},function(data){
		var dataValue = eval('('+data+')');
		if(dataValue.error!=null)
			{
			alert(dataValue.error);
			$("#realName").val("");
			$("#accountBalance").val("");
			$("#userNo").val("");
			return;
			
			}else{
	          //根据id查找对象，
	           var obj=document.getElementById("realName");
	           var userNo=document.getElementById("userNo");
	           
	           obj.value=dataValue.realName;
	           userNo.value=dataValue.id; //这个兼容IE与firefox
	           document.getElementById("accountBalance").value=dataValue.accountBalance;
		}
	},'json');
}

/*
 * 确定具体会员
 * @param {Object} prefix
 */
function checkUser(prefix){
	//小区
	var community = document.getElementById("community");
	var cNo=community.options[community.selectedIndex].value;
	//楼号
	var build = document.getElementById("buildNo");
	var buildNo=build.options[build.selectedIndex].value;
	//单元号
	var unit = document.getElementById("unitNo");
	var unitNo = unit.options[unit.selectedIndex].value;
	//会员号
	var room = document.getElementById("roomNo");
	var roomNo = room.options[room.selectedIndex].value;
	if(community!=""&&roomNo!="")
		{
	//查询关联的用户
	var url=prefix+"/companyAdmin/checkUser";
	$.post(url,{"community":cNo,"buildNo":buildNo,"unitNo":unitNo,"roomNo":roomNo},function(data){
		var dataValue = eval('('+data+')');
		if(dataValue.error!=null)
			{
			alert(dataValue.error);
			$("#realName").val("");
			$("#accountBalance").val("");
			$("#userNo").val("");
			return;
			
			}else{
	          //根据id查找对象，
	           var obj=document.getElementById("realName");
	           var userNo=document.getElementById("userNo");
	           
	           obj.value=dataValue.realName;
	           userNo.value=dataValue.id; //这个兼容IE与firefox
	           document.getElementById("accountBalance").value=dataValue.accountBalance;
		}
	},'json');
		}
}